#version 140

uniform vec3	UniColorDiffuse;
uniform vec3	UniColorAmbient;
uniform vec3	UniColorSpecular;

smooth in vec3 out_LightDir;
smooth in vec3 out_VertexNormal;

vec3	phongIllumination(vec3 lightDir, vec3 vertexNormal)
{
	vec3	color;
	float	coefDiffuse = max(0.0, dot(vertexNormal, lightDir));
	vec3	vecReflected = normalize(reflect(-lightDir, vertexNormal));
	float	coefSpec = max(0.0, dot(vertexNormal, vecReflected));
	
	color = UniColorDiffuse * coefDiffuse;
	color += UniColorAmbient;
	if (abs(coefSpec) > 0.005)
	{
		coefSpec = pow(coefSpec, 128.0);
		color += vec3(coefSpec);
	}
	return color;
}

void	main()
{
	gl_FragColor = vec4(phongIllumination(out_LightDir, out_VertexNormal), 1.0);
}


